/**
 * Copyright &copy; com.nmf
 */
package com.nmf.site.biz.workinfo.service;

import java.util.List;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nmf.site.common.PageDb;
import org.apache.commons.lang3.StringUtils;

import com.nmf.dao.gen.bean.BizWorkinfo;
import com.nmf.dao.gen.bean.BizWorkinfoExample;
import com.nmf.dao.gen.BizWorkinfoMapper;
import com.nmf.site.common.enums.DelFlagEnums;
import com.nmf.site.common.persistence.Page;
import com.nmf.site.common.utils.IdGenerater;

/**
 * 工作动态Service
 * @author bm
 * @version 2019-01-27
 */
@Service
@Transactional(readOnly = true)
public class BizWorkinfoService{

	@Autowired
	BizWorkinfoMapper bizWorkinfoMapper;
	@Autowired
	IdGenerater idGenerater;
	
	public BizWorkinfo get(String no) {
		return bizWorkinfoMapper.selectByPrimaryKey(no);
	}
	
	public List<BizWorkinfo> findList(BizWorkinfo bizWorkinfo) {
		BizWorkinfoExample bizWorkinfoExample = new BizWorkinfoExample();
		BizWorkinfoExample.Criteria criteria = bizWorkinfoExample.createCriteria();
		
		return bizWorkinfoMapper.selectByExample(bizWorkinfoExample);
	}
	
	public Page<BizWorkinfo> findPage(Page<BizWorkinfo> page, BizWorkinfo bizWorkinfo) {
		BizWorkinfoExample bizWorkinfoExample = new BizWorkinfoExample();
		BizWorkinfoExample.Criteria criteria = bizWorkinfoExample.createCriteria();
		if(bizWorkinfo.getWorkStatus()!=null) {
			criteria.andWorkStatusEqualTo(bizWorkinfo.getWorkStatus());
		}
		bizWorkinfoExample.setPage(page);
		
		List<BizWorkinfo> dlist = bizWorkinfoMapper.selectByExample(bizWorkinfoExample);
		page.setList(dlist);
		page.setCount(bizWorkinfoMapper.countByExample(bizWorkinfoExample));
		
		return page;
	}
	
	@Transactional(readOnly = false)
	public void save(BizWorkinfo bizWorkinfo) {
		if(StringUtils.isNotEmpty(bizWorkinfo.getId())&&get(bizWorkinfo.getId())!=null) {
			bizWorkinfoMapper.updateByPrimaryKeySelective(bizWorkinfo);
		}else {
			Date date = new Date();
			bizWorkinfo.setCreateDate(date);
			bizWorkinfo.setId(idGenerater.genClsNo("bizWorkinfo"));
			bizWorkinfo.setUpdateDate(date);
			bizWorkinfoMapper.insertSelective(bizWorkinfo);
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(BizWorkinfo bizWorkinfo) {
		bizWorkinfoMapper.deleteByPrimaryKey(bizWorkinfo.getId());
	}
	
}